package com.sitanyun.merchant.guide.frament.model.impl;

import com.google.gson.Gson;
import com.sitanyun.merchant.guide.bean.SwiShopsBean;
import com.sitanyun.merchant.guide.bean.SwishShopBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.frament.model.inter.ISwitchstoresAModel;
import com.sitanyun.merchant.guide.presenter.callback.CallBack;
import com.sitanyun.merchant.guide.url.Urls;
import com.sitanyun.merchant.guide.weiht.SharedPreferenceUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;

import okhttp3.Call;
import okhttp3.MediaType;

/**
 * 切换门店
 */
public class SwitchstoresAModelImpl implements ISwitchstoresAModel {
    @Override
    public <T> void setswich(CallBack callBack) {
        OkHttpUtils.get().url(Urls.storequery)
                .addHeader("Content-Type","application/x-www-form-urlencoded")
                .addHeader("Authorization","Bearer"+ SharedPreferenceUtil.getStringData("token"))

                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                SwishShopBean baseEntity=     new Gson().fromJson(response, SwishShopBean.class);
              callBack.onSuccess(baseEntity);
            }
        });
    }

    @Override
    public <T> void setswichsave(String staffId, String userId, String clientId, String nodeId , String secret, CallBack callBack) {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("staffId",staffId);
        hashMap.put("userId", userId);
        hashMap.put("clientId", clientId);//
        hashMap.put("nodeId",nodeId );//

        hashMap.put("secret",  secret);//
        OkHttpUtils.postString()
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .addHeader("Content-Type", "application/json")
             //   .addHeader("Authorization", "Bearer " + SharedPreferenceUtil.getStringData("token"))
                .url(Urls.manual)
                .content(new Gson().toJson(hashMap))
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {
            }
            @Override
            public void onResponse(String response, int id) {
                SwiShopsBean baseEntity= new Gson().fromJson(response, SwiShopsBean.class);
                callBack.onSuccess(baseEntity);
            }
        });
    }
}
